package com.youfan.re;

import lombok.Data;

/**
 * 通用返回结果
 * @param <T>
 */
@Data
public class Result<T> {
    private int code;
    private String message;
    private T data;

    public Result(){}

    public Result(int code,String message,T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }
    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCode.SUCCESSCODE, ResultCode.SUCCESSMESSAGE, data);
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     * @param  message 提示信息
     */
    public static <T> Result<T> success(T data, String message) {
        return new Result<T>(ResultCode.SUCCESSCODE, message, data);
    }


    public static <T> Result<T> fail() {
        return new Result<T>(ResultCode.FAILCODE, ResultCode.FAILMESSAGE, null);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<T>(ResultCode.FAILCODE, message, null);
    }
}
